package tuding.android.bigplanettracks.maps;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import android.util.Log;

import android.text.format.Time;

public class Logex {

	private static Logger logger = Logger.getLogger("MAIN");
	
	static{
		
		try {
			Formatter formatter = new Formatter() {

	            public String format(LogRecord arg0) {
	                StringBuilder b = new StringBuilder();
	                b.append(new Date());
	                b.append(" ");
	                //b.append(arg0.getSourceClassName());
	                //b.append(" ");
	                b.append(arg0.getSourceMethodName());
	                b.append(" ");
	                b.append(arg0.getLevel());
	                b.append(" ");
	                b.append(arg0.getMessage());
	                b.append(System.getProperty("line.separator"));
	                return b.toString();
	            }
			};

			logger.setUseParentHandlers(false);
			
			logger.setLevel(Level.ALL);
			FileHandler fileHandler = new FileHandler("/sdcard/tuding/log.txt");
			fileHandler.setFormatter(formatter);
			logger.addHandler(fileHandler);
			//ConsoleHandler conHdlr = new ConsoleHandler();
			//conHdlr.setFormatter(formatter);
			//logger.addHandler(conHdlr);
			LogManager lm = LogManager.getLogManager();
			lm.addLogger(logger);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	public static void message(String tag,String msg){
		String message = tag+":"+ msg; 
		logger.info(message);
		Log.d(tag, msg);
	}
	
		
}
